package com.wang.di.web.anno_executor;

import com.wang.di.core.handler.AnnoHandler;
import com.wang.di.core.handler.JustMethodProxy;
import com.wang.di.web.WebApplication;
import com.wang.di.web.anno.Controller;
import com.wang.di.web.anno.PostMapper;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class PostMapperExecutor extends AnnoHandler<PostMapper> {
    private WebApplication app;

    public PostMapperExecutor(WebApplication app) {
        this.app = app;
    }

    @Override
    public JustMethodProxy method(Object instance, Class<?> clz, Method method, PostMapper anno) throws Exception {
        Controller controller = clz.getAnnotation(Controller.class);
        String url = controller.value() + anno.value();
        this.app.register(url, req -> (String) method.invoke(instance));
        return null;
    }
}
